// 云函数入口文件
const cloud = require('wx-server-sdk')
const { default: axios } = require('axios')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境

// 云函数入口函数
exports.main = async (event, context) => {
  try {
    // const res = await axios.get('https://api.beatsaver.com/maps/latest')
    let {mapperId = 0} = event;
    let url = 'https://beatsaver.com/api/users/id/' + mapperId

    const res = await axios.get(url)
    return {
      status: 'OK',
      data: res.data
    }
  } catch(err){
    console.log(err)
    console.log(err.response.data)
    return {
      status: 'ERROR',
      error: err.message | 'Request failed!'
    }
  }
}